package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.seller.TbSeller;
import com.dongdongshop.service.seller.SellerService;
import com.dongdongshop.service.seller_jpa.SellerJpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("seller")
public class SellerController {
    @Reference
    private SellerService sellerService;
    private Logger logger = LoggerFactory .getLogger(SellerController.class);
    @Reference
    private SellerJpaService sellerJpaService;
    @RequestMapping("sellerAuditShow")
    public String sellerAudit(){
        return "admin/seller_1";
    }
    @RequestMapping("listSellerAudit")
    @ResponseBody
    public Result listSellerAudit(){
        try {
           /* List<TbSeller> listSellerAudit = sellerService.listSellerAudit();*/
            List<TbSeller> listSellerAudit = sellerJpaService.listSellerAudit();
            return Result.ok().setData(listSellerAudit);
        }catch (Exception e){
            logger.error("未审核商家查询失败");
            return Result.fail();
        }
    }
    //回显商家详情信息
    @RequestMapping("getSellerAudit")
    @ResponseBody
    public Result getSellerAudit(String sellerId){
        try {
            /*TbSeller tbSeller = sellerService.getSellerAudit(sellerId);*/
            TbSeller tbSeller = sellerJpaService.getSellerByUsername(sellerId);
            return Result.ok().setInfo(tbSeller);
        }catch (Exception e){
            logger.error("回显商家详情信息失败",e);
            return Result.fail();
        }
    }
    //审核操作
    @RequestMapping("updateSellerStatus")
    @ResponseBody
    public Result updateSellerStatus(String sellerId,String status){
        try {
/*
            int i = sellerService.updateSellerStatus(sellerId,status);
*/
            sellerJpaService.updateSellerStatus(sellerId,status);
            return Result.ok();
        }catch (Exception e){
            logger.error("审核错误",e);
            return Result.fail();
        }
    }

}
